<template>
<div>
    <h2>购物清单</h2>
    <el-table
    ref="multipleTable"
    :data="tableData"
    tooltip-effect="dark"
    style="width: 100%"
    @selection-change="handleSelectionChange">
    <el-table-column
      type="selection"
      width="55">
    </el-table-column>
<!-- 商品名称 -->
    <el-table-column
      label="商品名称"
      width="100">
      <template slot-scope="scope">
        <el-popover trigger="hover" placement="top" style="width:200px">
          <el-image :src="scope.row.logo"></el-image>
          <p>{{ scope.row.name }}</p>
          <div slot="reference" class="name-wrapper">
            <el-tag size="medium">{{ scope.row.name }}</el-tag>
          </div>
        </el-popover>
      </template>
    </el-table-column>

<!-- 单价 -->
    <el-table-column
      label="单价"
      width="180">
      <template slot-scope="scope">
        <span style="margin-left: 10px"> {{ scope.row.price }}</span>
      </template>
    </el-table-column>
<!-- 数量 -->
    <el-table-column
      label="数量"
      width="180">
      <template slot-scope="scope">
         <el-input-number v-model="scope.row.count" :min="0" :max="10" label="描述文字" style="width:120px"
          ></el-input-number>
      </template>
    </el-table-column>
<!-- 总价钱 -->
    <el-table-column
      label="总价"
      width="180">
      <template slot-scope="scope">
        <span style="margin-left: 10px"
        >{{ scope.row.count*scope.row.price }}</span>
      </template>
    </el-table-column>
<!-- 操作 -->
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
  <div>
     <p>总金额：{{tableData[1].price*tableData[1].count}}</p>
   </div>
  <div style="margin-top: 20px">
    <el-button @click="toggleSelection()">取消选择</el-button>
  </div>
</div>
  
</template>

<script>
let trs = document.getElementsByTagName("tr");
  export default {
    data() {
      return {
        sum:0,
        num:"",
        tableData: [
        { id:1,
        name:"AJ",
        count:2,price:1999,logo:require("./img/1.webp")},
        { id:2,
        name:"厨具",count:2,
        price:899,logo:require("./img/2.webp")},
        { id:3,
        name:"口红",count:1,price:4699,logo:require("./img/3.webp")}
       ],
        multipleSelection: []
      }
    },
    methods: {
      toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
        console.log(val)
      },
      handleDelete(index, row) {
        console.log(index, row);
        console.log(row)
        trs[index+1].innerHTML = "";
      },
    },
    watch:{
      tableData:{
        deep:true,
        handler(val,old){
          this.num = old
          console.log(this.num[0].count);
        }
      }
    }
  }
</script>
